#    Rubatom
#    Copyright (c) 2014 Sebastian Dufner
#
#    This file is part of Rubatom.
#
#    Rubatom is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    Rubatom is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.

class IO

  ##
  # Reads a 32 bit integer from the I/O stream.

  def read_i32
    read(4).unpack('i>').first
  end
  alias_method :read_i, :read_i32

  ##
  # Reads a 16 bit integer from the I/O stream.

  def read_i16
    read(2).unpack('h>').first
  end

  ##
  # Reads a 64 bit integer from the I/O stream.

  def read_i64
    read(8).unpack('q>').first
  end

  ##
  # Reads an 8 bit integer from the I/O stream.

  def read_i8
    read(1).unpack('c').first
  end

  ##
  # Reads a 32 bit float from the I/O stream.

  def read_f32
    read(4).unpack('g').first
  end
  alias_method :read_f, :read_f32

  ##
  # Reads a 64 bit float from the I/O stream.

  def read_f64
    read(8).unpack('G').first
  end
  alias_method :read_double, :read_f64
end
